import Vue from 'vue'
import Router from 'vue-router'


Vue.use(Router)

// router.beforeEach((to, from, next) => {
//   if (store.getters.token) { // 判断是否有token
//     if (to.path === '/login') {
//       next({ path: '/' });
//     } else {
//       if (store.getters.roles.length === 0) { // 判断当前用户是否已拉取完user_info信息
//         store.dispatch('GetInfo').then(res => { // 拉取info
//           const roles = res.data.role;
//           store.dispatch('GenerateRoutes', { roles }).then(() => { // 生成可访问的路由表
//             router.addRoutes(store.getters.addRouters) // 动态添加可访问路由表
//             next({ ...to, replace: true }) // hack方法 确保addRoutes已完成 ,set the replace: true so the navigation will not leave a history record
//           })
//         }).catch(err => {
//           console.log(err);
//         });
//       } else {
//         next() //当有用户权限的时候，说明所有可访问路由已生成 如访问没权限的全面会自动进入404页面
//       }
//     }
//   } else {
//     if (whiteList.indexOf(to.path) !== -1) { // 在免登录白名单，直接进入
//       next();
//     } else {
//       next('/login'); // 否则全部重定向到登录页
//     }
//   }
// });



export const constantRouterMap = [
  {
    path: '/login',
    name: 'login',
    component: () => import('@/views/other/login'),
    meta: { title: '登陆' }
  },
  {
    path: '/',
    name: 'home',
    component: () => import('./views/Home.vue'),
    meta: { title: '首页' },
    redirect: '/bigScreen',
    children: [
      {
        path: '/bigScreen',
        name: 'bigScreen',
        component: () => import('./views/layout/bigScreen'),
        meta: { title: '大屏布局' }
      }
    ]
  },
  {
    path: '*',
    name: 'error',
    component: () => import('@/views/other/error'),
    meta: { title: '404' }
  }
]

export const asyncRouterMap = [
  {
    path: '/',
    name: 'home',
    component: () => import('./views/Home.vue'),
    meta: { title: '首页' },
    redirect: '/bigScreen',
    children: [
      {
        path: '/info',
        name: 'info',
        component: () => import('./views/info.vue'),
        meta: { title: '城市选择' }
      },
      {
        path: '/signutare',
        name: 'signutare',
        component: () => import('./views/signutare.vue'),
        meta: { title: '签字' }
      },
      {
        path: '/demo',
        name: 'demo',
        component: () => import('./views/demo.vue'),
        meta: { title: 'vuex' }
      },
      // screenshot
      {
        path: '/screenshot',
        name: 'screenshot',
        component: () => import('./views/screenshot.vue'),
        meta: { title: 'screenshot' }
      },
      {
        path: '/drag',
        name: 'drag',
        component: () => import('./views/drag.vue'),
        meta: { title: 'drag' }
      },
      {
        path: '/drag1',
        name: 'drag1',
        component: () => import('./views/drag1.vue'),
        meta: { title: 'drag1' }
      },
      {
        path: '/drag2',
        name: 'drag2',
        component: () => import('./views/drag2.vue'),
        meta: { title: 'drag2' }
      },
      {
        path: '/drag3',
        name: 'drag3',
        component: () => import('./views/drag3.vue'),
        meta: { title: 'drag3' }
      },
      {
        path: '/parameter',
        name: 'parameter',
        component: () => import('./views/parameter.vue'),
        meta: { title: '组件传参' }
      },
      {
        path: '/counter',
        name: 'counter',
        component: () => import('./views/counter.vue'),
        meta: { title: '计数器' }
      },
      {
        path: '/colorChange',
        name: 'colorChange',
        component: () => import('./views/colorChange.vue'),
        meta: { title: '颜色进制转换' }
      },

      {
        path: '/download',
        name: 'download',
        component: () => import('./views/downloads.vue'),
        meta: { title: '表格合并' }
      },
      {
        path: '/maps',
        name: 'maps',
        component: () => import('./views/maps.vue'),
        meta: { title: '云南地图' }
      },
      {
        path: '/mapDs',
        name: 'mapDs',
        component: () => import('./views/mapDs.vue'),
        meta: { title: '散点图' }
      },
      {
        path: '/qpEcharts',
        name: 'qpEcharts',
        component: () => import('./views/echart/qpEcharts.vue'),
        meta: { title: '色温气泡图' }
      },
      {
        path: '/rankEcharts',
        name: 'rankEcharts',
        component: () => import('./views/echart/rankEcharts.vue'),
        meta: { title: '排名地图' }
      },
      {
        path: '/dynamicEcharts',
        name: 'dynamicEcharts',
        component: () => import('./views/echart/dynamicEcharts.vue'),
        meta: { title: '动态折线图' }
      },
      {
        path: '/hotEcharts',
        name: 'hotEcharts',
        component: () => import('./views/echart/hotEcharts'),
        meta: { title: '热力图' }
      },

      {
        path: '/mapChange',
        name: 'mapChange',
        component: () => import('./views/echart/mapChange'),
        meta: { title: '地图切换' }
      },
      {
        path: '/mapC',
        name: 'mapC',
        component: () => import('./views/echart/mapC'),
        meta: { title: '地图下钻' }
      },
      {
        path: '/mapEchart',
        name: 'mapEchart',
        component: () => import('./views/echart/mapEchart'),
        meta: { title: "空气质量散点图" }
      },
      {
        path: '/tableChange',
        name: 'tableChange',
        component: () => import('./views/table/tableChange'),
        meta: { title: '表格合并' }
      },
      {
        path: '/tableset',
        name: 'tableset',
        component: () => import('./views/table/index'),
        meta: { title: '表格合并2' }
      },
      {
        path: '/sdljEcharts',
        name: 'sdljEcharts',
        component: () => import('./views/echart/sdljEcharts'),
        meta: { title: '散点/关系图' }
      },
      {
        path: '/ljtEcharts',
        name: 'ljtEcharts',
        component: () => import('./views/echart/ljtEcharts'),
        meta: { title: '关系图' }
      },
      {
        path: '/ddzztEcharts',
        name: 'ddzztEcharts',
        component: () => import('./views/echart/ddzztEcharts'),
        meta: { title: '堆叠柱状图' }
      },
      {
        path: '/pieEcharts',
        name: 'pieEcharts',
        component: () => import('./views/echart/pieEcharts'),
        meta: { title: '饼图' }
      },
      {
        path: '/cnConvertpy',
        name: 'cnConvertpy',
        component: () => import('./views/common/chineseConvertpinyin'),
        meta: { title: '汉字转拼音首字母' }
      }, {
        path: '/pieEchart',
        name: 'pieEchart',
        component: () => import('./views/echart/pieEchart'),
        meta: { title: '图标嵌套环形图' }
      },
     
      {
        path: '/bigScreen',
        name: 'bigScreen',
        component: () => import('./views/layout/bigScreen'),
        meta: { title: '大屏布局' }
      },
     
    ]
  },
  {
    path: '/login',
    name: 'login',
    component: () => import('@/views/other/login'),
    meta: { title: '登陆' }
  },
  {
    path: '*',
    name: 'error',
    component: () => import('@/views/other/error'),
    meta: { title: '404' }
  }
]


export default new Router({
  routes: asyncRouterMap
});



